﻿using Buddy;
using Buddy.Corpus.WinSvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace $safeprojectname$
{
    static partial class Program
    {
        static void Main(string[] args)
        {
            var flags = new Args();

            if (flags["h"].IsSupplied() || flags["help"].IsSupplied())
            {
                ShowHelp();

                return;
            }

            var svc = new $safeprojectname$Svc();

            // You can debug your code in Visual Studio by uncommenting this code:
            //new InConsole(svc).Run();
            //return;
            // Press Ctrl+C to stop.

            if (flags["i"].IsSupplied() || flags["install"].IsSupplied()) SvcInstaller.Install(false, args);
            else if (flags["u"].IsSupplied() || flags["uninstall"].IsSupplied()) SvcInstaller.Install(true, args);
            else if (flags["start"].IsSupplied()) new SvcController().Start();
            else if (flags["stop"].IsSupplied()) new SvcController().Stop();
            else if (flags["c"].IsSupplied() || flags["console"].IsSupplied()) new InConsole(svc).Run();
            else new InSvc(svc).Run();
        }

        static void ShowHelp()
        {
            Console.WriteLine("-h or -help          shows this help");
            Console.WriteLine("-i or -install       installs this windows service");
            Console.WriteLine("-u or -uninstall     uninstalls this windows service");
            Console.WriteLine("-start               starts this windows service");
            Console.WriteLine("-stop                stops this windows service");
            Console.WriteLine("-c or -console       runs this windows service as a console application");
        }
    }
}
